namespace Crux.Core.Websockets;
/// <summary>
///
/// </summary>
internal class UserClientProxy(ILifetimeManager lifetimeManager, string userId) : IClientProxy
{
    /// <summary>
    ///
    /// </summary>
    private readonly ILifetimeManager _manager = lifetimeManager ?? throw new ArgumentNullException(nameof(lifetimeManager));
    /// <summary>
    ///
    /// </summary>
    private readonly string userId = userId ?? throw new ArgumentNullException(nameof(userId));
    /// <summary>
    ///
    /// </summary>
    /// <param name="method"></param>
    /// <param name="args"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task SendCoreAsync(
        string method,
        object[] args,
        CancellationToken cancellationToken = default)
        => _manager.SendUserAsync(userId, method, args, cancellationToken);
}
/// <summary>
///
/// </summary>
internal class GroupClientProxy(ILifetimeManager lifetimeManager, string groupName) : IClientProxy
{
    /// <summary>
    ///
    /// </summary>
    private readonly ILifetimeManager _manager = lifetimeManager ?? throw new ArgumentNullException(nameof(lifetimeManager));
    /// <summary>
    ///
    /// </summary>
    private readonly string groupName = groupName ?? throw new ArgumentNullException(nameof(groupName));
    /// <summary>
    ///
    /// </summary>
    /// <param name="method"></param>
    /// <param name="args"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task SendCoreAsync(string method, object[] args, CancellationToken cancellationToken = default)
        => _manager.SendGroupAsync(groupName, method, args, cancellationToken);
}
/// <summary>
///
/// </summary>
internal class AllClientProxy(ILifetimeManager lifetimeManager) : IClientProxy
{
    /// <summary>
    ///
    /// </summary>
    private readonly ILifetimeManager _manager = lifetimeManager ?? throw new ArgumentNullException(nameof(lifetimeManager));
    /// <summary>
    ///
    /// </summary>
    /// <param name="method"></param>
    /// <param name="args"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task SendCoreAsync(
        string method,
        object[] args,
        CancellationToken cancellationToken = default)
        => this._manager.SendAllAsync(method, args, cancellationToken);
}
/// <summary>
///
/// </summary>
internal class AllExceptClientProxy(ILifetimeManager lifetimeManager, params string[] exceptConnectionIds) : IClientProxy
{
    /// <summary>
    ///
    /// </summary>
    private readonly ILifetimeManager _manager = lifetimeManager ?? throw new ArgumentNullException(nameof(lifetimeManager));
    /// <summary>
    ///
    /// </summary>
    private readonly IReadOnlyList<string> exceptConnectionIds = exceptConnectionIds;
    /// <summary>
    ///
    /// </summary>
    /// <param name="method"></param>
    /// <param name="args"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task SendCoreAsync(
        string method,
        object[] args,
        CancellationToken cancellationToken = default)
        => _manager.SendAllExceptAsync(method, args, exceptConnectionIds, cancellationToken);
}
/// <summary>
/// /
/// </summary>
internal class ConnectionClientProxy(
        ILifetimeManager lifetimeManager,
        string connectionId) : IClientProxy
{
    /// <summary>
    ///
    /// </summary>
    private readonly ILifetimeManager _manager = lifetimeManager ?? throw new ArgumentNullException(nameof(lifetimeManager));
    /// <summary>
    ///
    /// </summary>
    private readonly string connectionId = connectionId ?? throw new ArgumentNullException(nameof(connectionId));
    /// <summary>
    ///
    /// </summary>
    /// <param name="method"></param>
    /// <param name="args"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task SendCoreAsync(
        string method,
        object[] args,
        CancellationToken cancellationToken = default)
        => _manager.SendConnectionAsync(connectionId, method, args, cancellationToken);
}
/// <summary>
///
/// </summary>
internal class ConnectionsClientProxy(ILifetimeManager lifetimeManager, params string[] connectionIds) : IClientProxy
{
    /// <summary>
    ///
    /// </summary>
    private readonly ILifetimeManager _manager = lifetimeManager ?? throw new ArgumentNullException(nameof(lifetimeManager));
    /// <summary>
    ///
    /// </summary>
    private readonly IReadOnlyList<string> connectionIds = connectionIds ?? throw new ArgumentNullException(nameof(connectionIds));
    /// <summary>
    ///
    /// </summary>
    /// <param name="method"></param>
    /// <param name="args"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task SendCoreAsync(string method, object[] args, CancellationToken cancellationToken = default)
        => _manager.SendConnectionsAsync(connectionIds, method, args, cancellationToken);
}
/// <summary>
///
/// </summary>
internal class GroupsClientProxy(ILifetimeManager lifetimeManager, params string[] groupNames) : IClientProxy
{
    /// <summary>
    ///
    /// </summary>
    private readonly ILifetimeManager _manager = lifetimeManager ?? throw new ArgumentNullException(nameof(lifetimeManager));
    /// <summary>
    ///
    /// </summary>
    private readonly IReadOnlyList<string> groupNames = groupNames ?? throw new ArgumentNullException(nameof(groupNames));
    /// <summary>
    ///
    /// </summary>
    /// <param name="method"></param>
    /// <param name="args"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task SendCoreAsync(
        string method,
        object[] args,
        CancellationToken cancellationToken = default)
        => _manager.SendGroupsAsync(groupNames, method, args, cancellationToken);
}
/// <summary>
///
/// </summary>
internal class UsersClientProxy(ILifetimeManager lifetimeManager, IReadOnlyList<string> userIds) : IClientProxy
{
    /// <summary>
    ///
    /// </summary>
    private readonly ILifetimeManager _manager = lifetimeManager ?? throw new ArgumentNullException(nameof(lifetimeManager));
    /// <summary>
    ///
    /// </summary>
    private readonly IReadOnlyList<string> userIds = userIds ?? throw new ArgumentNullException(nameof(userIds));
    /// <summary>
    ///
    /// </summary>
    /// <param name="method"></param>
    /// <param name="args"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task SendCoreAsync(
        string method,
        object[] args,
        CancellationToken cancellationToken = default)
        => _manager.SendUsersAsync(userIds, method, args, cancellationToken);
}
/// <summary>
///
/// </summary>
internal class GroupExceptClientProxy(ILifetimeManager lifetimeManager, string groupName, IReadOnlyList<string> exceptConnectionIds) : IClientProxy
{
    /// <summary>
    ///
    /// </summary>
    private readonly ILifetimeManager _manager = lifetimeManager ?? throw new ArgumentNullException(nameof(lifetimeManager));
    /// <summary>
    ///
    /// </summary>
    private readonly IReadOnlyList<string> exceptConnectionIds = exceptConnectionIds ?? throw new ArgumentNullException(nameof(exceptConnectionIds));
    /// <summary>
    ///
    /// </summary>
    private readonly string groupName = groupName ?? throw new ArgumentNullException(nameof(groupName));
    /// <summary>
    ///
    /// </summary>
    /// <param name="method"></param>
    /// <param name="args"></param>
    /// <param name="cancellationToken"></param>
    /// <returns></returns>
    public Task SendCoreAsync(
        string method,
        object[] args,
        CancellationToken cancellationToken = default)
        => _manager.SendGroupExceptAsync(groupName, method, args, exceptConnectionIds, cancellationToken);
}
